<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var arr1_temp = [1,2,4,5]
        var result = arr1_temp.unshift('zzz')
        console.log(result)
        console.log(arr1_temp)

        //练习1
        function Practice1(){
            var age_array_string = prompt('输入5个0到100的年龄，用空格隔开！',"2 nan cai 2 9")
            var temp = age_array_string.trim().split(' ')
            var age_array = []
            for (var age of temp){
                if(age){
                    num_age = parseInt(age)
                    if(isNaN(num_age)){
                        alert('你输入的数据有误！')
                        return 0
                    }else{
                        age_array.push(num_age)
                    }
                }
            }
            var age_below_18 = []
            for (var age of age_array){
                if(age >= 18)age_below_18.push(age)
            }
            console.log(age_below_18)
            var sum = 0
            var max_age = age_array[0]
            var min_age = age_array[0]
            for (var age of age_array){
                sum += age
                if(age > max_age)max_age = age
                if(age < min_age)min_age = age
            }
            console.log(`年龄总和为${sum}`)
            console.log(`年龄平均为${sum/age_array.length}`)
            console.log(`最大年龄${max_age}`)
            console.log(`最小年龄${min_age}`)
            alert(`年龄总和为${sum},年龄平均为${sum/age_array.length},最大年龄${max_age},最小年龄${min_age}`)
        }
        // Practice1()

        // 练习2
        let array1 = [10,23,10,50,65,99,10]
        let array2 = [2,4,6,83,29,19,33,234]
        function Practice2(array1){
            let temp_begin = 0
            let index1 = -1

            do {
                index1 = array1.indexOf(10,temp_begin)
                temp_begin = index1 + 1
                console.log(index1)
            } while (index1 !== -1);

        }
        // Practice2(array2)

        // 练习3
        function Practice3(array){
            let sum = 0
            for (let i of array){
                sum += i
            }
            console.log(`练习3的结果是${sum}`)
        }
        // Practice3([5, 8, 9, 2, 1, 5])

        //练习4
        function Practice4(array){
            let sum = 0
            for (let i = 0; i < array.length; i++){
                if (i > 5){
                    sum += array[i]
                }
            }
            console.log(`练习4的结果是${sum}`)
        }
        // Practice4([4, 9, 5, 20, 3, 11])
        
    </script>
</head>
<body>
    
</body>
</html>